import scrapy
import messAround.util.help as util


# 优酷热搜 splash
# https://acz.youku.com/wow/ykpage/act/top_hot
# https://acs.youku.com/h5/mtop.youku.soku.yksearch/2.0/?jsv=2.5.7&appKey=23774304&t=1599741690504&sign=8f35bdb0099568040b96c70951587f9f&api=mtop.youku.soku.yksearch&type=originaljson&v=2.0&ecode=1&dataType=json&data=%7B%22pg%22%3A%221%22%2C%22pz%22%3A%2210%22%2C%22appScene%22%3A%22default_page%22%2C%22appCaller%22%3A%22youku-search-sdk%22%7D
class YoukuTopSpider(scrapy.Spider):
    name = 'youku_top'
    allowed_domains = ['acz.youku.com']
    start_urls = ['https://acz.youku.com/wow/ykpage/act/top_hot']

    def start_requests(self):
        url = 'https://acz.youku.com/wow/ykpage/act/top_hot'
        yield scrapy.Request(url=url, callback=self.parse, headers=util.default_headers)

    def parse(self, response):
        print(response.text)
        for index in range(1, 7):
            for key in range(1, 11):
                item_xpath = f'/html/body/div[2]/div/div[3]/div/div[{index}]/a[{key}]/span[2]'
                print(item_xpath)
                keyword = response.xpath(f'{item_xpath}/text()').get()
                yield {
                    # 'no': index+":"+key,
                    'keyword': keyword,
                    'link': 'https://so.youku.com/search_video/q_' + keyword,
                }
        pass
